package listener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebListener
public class RequestAttributeListener implements ServletRequestAttributeListener {


    @Override
    public void attributeAdded(ServletRequestAttributeEvent srae) {
        //request作用域添加属性时触发执行
        HttpServletRequest request = (HttpServletRequest) srae.getServletRequest();
        System.out.println("request作用域添加"+srae.getName()+"属性,属性值:"+
                request.getAttribute(srae.getName()));
    }

    @Override
    public void attributeRemoved(ServletRequestAttributeEvent srae) {
        //request作用域移除属性时触发执行
        HttpServletRequest request = (HttpServletRequest) srae.getServletRequest();
        System.out.println("request作用域移除"+srae.getName()+"属性,属性值:"+
                request.getAttribute(srae.getName()));
    }

    @Override
    public void attributeReplaced(ServletRequestAttributeEvent srae) {
        //request作用域修改属性时触发执行
        HttpServletRequest request = (HttpServletRequest) srae.getServletRequest();
        System.out.println("request作用域修改"+srae.getName()+"属性,属性值:"+
                request.getAttribute(srae.getName()));
    }
}
